/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.ts.manager.impl;

import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

import com.xy.biz.ts.domain.po.ExaminationPaperQuestionPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.biz.ts.domain.bo.ExaminationPaperQuestionBO;
import com.xy.biz.ts.domain.query.ExaminationPaperQuestionQuery;
import com.xy.biz.ts.domain.converter.ExaminationPaperQuestionConverter;
import com.xy.biz.ts.manager.ExaminationPaperQuestionManager;
import com.xy.biz.ts.dao.ExaminationPaperQuestionDao;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 *
 * @author wwj
 * @date 2021-3-23
 */
@Service
public class ExaminationPaperQuestionManagerImpl implements ExaminationPaperQuestionManager {

    @Autowired
    private ExaminationPaperQuestionDao examinationPaperQuestionDao;

    @Override
    public int saveExaminationPaperQuestion(ExaminationPaperQuestionBO examinationPaperQuestionBO) {
        return examinationPaperQuestionDao.saveExaminationPaperQuestion(ExaminationPaperQuestionConverter.toPO(examinationPaperQuestionBO));
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveAllExaminationPaperQuestion(Collection<ExaminationPaperQuestionBO> collection) {
        Set<Long> paperIdList = collection.stream().map(ExaminationPaperQuestionBO::getExaminationPaperId).collect(Collectors.toSet());
        deleteExaminationPaperQuestionsByPaperId(paperIdList);
        return examinationPaperQuestionDao.saveAllExaminationPaperQuestion(ExaminationPaperQuestionConverter.toPO(collection));
    }

    @Override
    public int updateExaminationPaperQuestion(ExaminationPaperQuestionBO examinationPaperQuestionBO) {
        return examinationPaperQuestionDao.updateExaminationPaperQuestion(ExaminationPaperQuestionConverter.toPO(examinationPaperQuestionBO));
    }

    @Override
    public int deleteExaminationPaperQuestion(Long examinationPaperQuestionId) {
        return examinationPaperQuestionDao.deleteExaminationPaperQuestion(examinationPaperQuestionId);
    }

    @Override
    public ExaminationPaperQuestionBO getExaminationPaperQuestion(Long examinationPaperQuestionId) {
        return null;
    }

//	@Override
//	public ExaminationPaperQuestionBO getExaminationPaperQuestion(Long examinationPaperQuestionId) {
//		return ExaminationPaperQuestionConverter.fromPO(examinationPaperQuestionDao.getExaminationPaperQuestion(examinationPaperQuestionId));
//	}

    @Override
    public List<ExaminationPaperQuestionBO> listExaminationPaperQuestionById(Collection<Long> collection) {
        return ExaminationPaperQuestionConverter.fromPO(examinationPaperQuestionDao.listExaminationPaperQuestionById(collection));
    }

    @Override
    public List<ExaminationPaperQuestionBO> listExaminationPaperQuestion(ExaminationPaperQuestionQuery query) {
        return ExaminationPaperQuestionConverter.fromPO(examinationPaperQuestionDao.listExaminationPaperQuestion(query));
    }

    @Override
    public int countExaminationPaperQuestion(ExaminationPaperQuestionQuery query) {
        return examinationPaperQuestionDao.countExaminationPaperQuestion(query);
    }

    @Override
    public void deleteExaminationPaperQuestionsByPaperId(Collection<Long> examinationPaperId) {
        examinationPaperQuestionDao.deleteExaminationPaperQuestionsByPaperId(examinationPaperId);
    }

    @Override
    public int deleteExaminationPaperQuestionByExaminationPaperId(ExaminationPaperQuestionPO toPO) {
        return examinationPaperQuestionDao.deleteExaminationPaperQuestionByExaminationPaperId(toPO);
    }

}
